#!/usr/bin/env python
# -*- coding: UTF-8 -*-
'''
@Project ：hiflyworks_web_tests 
@File    ：report.py.py
@Author  ：beibei
@Date    ：2025/6/20 7:13 PM 
'''
import base64
from pathlib import Path


def attach_image(request, image_path):
    plugin_manager = request.config.pluginmanager
    if 'html' in plugin_manager._name2plugin:
        html_plugin = plugin_manager.get_plugin("html")
        extra = getattr(request.node, 'extra', [])
        with open(image_path, "rb") as f:
            b64 = base64.b64encode(f.read()).decode("utf-8")
        extra.append(html_plugin.extras.image(f"data:image/png;base64,{b64}"))
        request.node.extra = extra
